<template>
    <div>
    <el-form inline class="demo-form-inline">
    <el-row >
    <el-col :span="6">
        <el-form-item label="表名">
            <el-input v-model="query.payload.tableName" placeholder="" />
        </el-form-item>
    </el-col>
    <el-col :span="6">
        <el-form-item label="注释">
            <el-input v-model="query.payload.tableComment" placeholder="" />
        </el-form-item>
    </el-col>
    </el-row>
    <el-row >
        <el-form-item label="时间范围">
            <el-date-picker
                    v-model="query.dateRange"
                    type="datetimerange"
                    range-separator="到"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" plain activity @click="queryGenerator">查询</el-button>
            <el-button type="primary" plain activity @click="reset">重置</el-button>
            <el-button type="primary" plain @click="addGenerator">新增</el-button>
        </el-form-item>
    </el-row>
    </el-form>
    <el-divider style="margin: 12px 0"/>
    <el-table ref="table" border v-loading="loading"  :data="data.tableData" header-cell-class-name="headerClass">
        <el-table-column align="center" type="index"  label="序号" width="100px" />
        <el-table-column align="center" prop="tableName" label="表名" />
        <el-table-column align="center" prop="tableComment" label="注释" />
        <el-table-column align="center"  prop="createTime" label="创建时间" >
            <template #default="scope">
                {{moment(scope.row.updateTime).format("yyyy-MM-DD HH:mm:ss")}}
            </template>
        </el-table-column>
        <el-table-column align="center"  label="操作">
            <template #default="scope">
                <el-popconfirm title="确定生成代码？" @confirm="toGenerator(scope.row.tableName)"  @cancel="">
                    <template #reference>
                        <el-link type="primary" title="生成">
                            <el-icon :size="20">
                                <Setting />
                            </el-icon>
                        </el-link>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
</el-table>
<el-pagination
        style="display: flex;align-items:center;justify-content:center;"
        v-model:currentPage="query.currentPage"
        v-model:page-size="query.pageSize"
        :page-sizes="[10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
        @size-change="queryGenerator"
        @current-change="queryGenerator"
/>
    <ModGenerator @close="data.modGenerator = false" :modGenerator="data.modGenerator" :tableName="data.tableName" />
    </div>
</template>

<script setup>
    import ModGenerator from '@/components/system/ModGenerator.vue'
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    import {ref, reactive, onMounted} from 'vue'
    import moment from 'moment'

    let data = reactive({
        modRole:false,
        roleToMenu:false,
        tableData:[],
        type:"",
        id:"",
    });
    let loading = ref(true)
    let query = reactive({dateRange:[],payload:{}, currentPage:1,pageSize:10,total:0})
    onMounted(() => {
        queryGenerator()
    })
    function queryGenerator(){
        query.startTime = query.dateRange[0]
        query.endTime = query.dateRange[1]
        request.post("/api/generator/getGeneratorPage", query).then(resp => {
            data.tableData = resp.records
            query.total = resp.total
            loading.value = false
        })
    }

    function reset(){
            query.payload.tableName = ""
            query.payload.tableComment = ""
    }

    function addGenerator(){
        data.modGenerator = true
        data.type = "add"
    }

    function deleteGenerator(id){
        request.get(`/api/generator/delete/${id}`).then(resp => {
            queryGenerator()
            ElMessage({message: '删除成功！',type: 'success'})
        });
    }
    function toGenerator(tableName){
        data.tableName = tableName
        data.modGenerator = true
    }



</script>
<style lang="css">

</style>


